//
//  XLVistor.swift
//  WeiBo
//
//  Created by macbook on 16/10/17.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit
import SnapKit

class XLVistor: UIView {

    var close : (()->())?
    
 
    override init(frame: CGRect) {
        super.init(frame: frame)
        
       setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI()
    {
        backgroundColor = RBG(237, green: 237, blue: 237)
        addSubview(feedImageView)
        addSubview(maskImageView)
        addSubview(houseImageView)
        addSubview(contentLabel)
        addSubview(loginBtn)
        addSubview(registerBtn)
        
        //添加约束
        feedImageView.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
        }
        
        maskImageView.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
        }
        
        houseImageView.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
        }
        
        contentLabel.snp_makeConstraints { (make) in
            
            make.width.equalTo(224)
            make.height.equalTo(36)
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.centerX.equalTo(maskImageView)
        }
        
        loginBtn.snp_makeConstraints { (make) in
            
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(16)
        }
        
        registerBtn.snp_makeConstraints { (make) in
            
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.right.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(16)
        }

    }
    
    //懒加载,加载添加控件
    //圆圈
    private lazy var feedImageView:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    //遮罩
    private lazy var maskImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
    //房子
    private lazy var houseImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
    
    //文字
    private lazy var contentLabel:UILabel = {
    
        let label = UILabel()
        
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        label.numberOfLines = 0
        label.font = UIFont.systemFontOfSize(14)
        label.textAlignment = NSTextAlignment.Center

        return label
    }()
    
    
    //登陆
    private lazy var loginBtn:UIButton = {
    
        let loginBtn = UIButton()
        
        loginBtn.setTitle("登录", forState: UIControlState.Normal)
        loginBtn.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        loginBtn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        loginBtn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        //添加方法
        loginBtn.addTarget(self, action: #selector(XLVistor.loginBtnClick), forControlEvents: UIControlEvents.TouchUpInside)
        
        return loginBtn
    }()
    
    
    
    //注册
    lazy var registerBtn: UIButton = {
        
        let btn = UIButton()
        btn.setTitle("登录", forState: UIControlState.Normal)
        btn.setTitleColor(ThemeColor, forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        //添加方法
        btn.addTarget(self, action: #selector(XLVistor.loginBtnClick), forControlEvents: .TouchUpInside)
        
        return btn
    }()

    
    
    
    // MARK: - 登陆
    func loginBtnClick(){
        
        close?()
        
    }
    
    
    
    //旋转
    func setAnimate()
    {
        let animate = CABasicAnimation(keyPath: "transform.rotation")
        //设置动画时间
        animate.duration = 15
        animate.toValue = M_PI_2 * 2
        animate.repeatCount = MAXFLOAT
        animate.removedOnCompletion = false
        //添加动画
        feedImageView.layer.addAnimation(animate, forKey: nil)
    }
    
    
    //外界调用
    func setupVistorInfor(imageName:String?,title:String?)
    {
        if let imagee = imageName,let tit = title {
            houseImageView.image = UIImage(named: imagee)
            contentLabel.text = tit
            
            //影藏圆圈
            feedImageView.hidden = true
        }else//主页
        {
            setAnimate()
        }
    }
    

 
    
}







